package it.univaq.di.helpdesk.common;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;

public class AjaxGlobalExceptionHandler extends ExceptionHandler {
	private Log logger = LogFactory.getLog(AjaxGlobalExceptionHandler.class);
	
	@Override
	public ActionForward execute(Exception ex, ExceptionConfig ae,
			ActionMapping mapping, ActionForm formInstance,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException {
		
		logger.debug("Exception while processing AJAX request " + request.getRequestURI(), ex);
		
		try {
			response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		} catch (IOException e) {
			logger.debug("Error during exception handling for AJAX request " + request.getRequestURI(), e);
		}
		
		return null;
	}
}
